package com.woniu.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.bean.R;
import com.woniu.order.bean.TOrder;
import com.woniu.order.mapper.TOrderMapper;
import com.woniu.order.service.ITOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yellowDocter
 * @since 2022-08-08
 */
@Service
    public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {
        @Override
        public R selectall(Integer currentPage, Integer pageSize, Integer number, String username) {
            System.out.println("currentPage = " + currentPage);
            System.out.println("pageSize = " + pageSize);
            System.out.println("number = " + number);
            System.out.println("username = " + username);
            R r= null;
            QueryWrapper qw=new QueryWrapper();
            if(number!=null){
                qw.eq("order_id",number);
            }
            if(username!=null&&username!=""){
                qw.like("username",username);
            }
            IPage<TOrder> iPage=new Page<>(currentPage,pageSize);
            IPage<TOrder> page = this.page(iPage,qw);
            List<TOrder> records = page.getRecords();
            System.out.println("records = " + records);
            long total = page.getTotal();
            r=R.OK();
            Map map=new HashMap<>();
            map.put("records", records);
            map.put("total", total);
            r.setData(map);
            return r;
        }
    }
